    var DeviceMain;//主头
	var Video;//视频
	var device=false;//视频

	
	function plugin()
    {
        return document.getElementById('view');
    }

    function view()
    {
        return document.getElementById('view');
    }
    
	function ocr()
    {
        return document.getElementById('ocr');
    }
    	
	
	function addEvent(obj, name, func)
    {
        if (obj.attachEvent) {
            obj.attachEvent("on"+name, func);
        } else {
            obj.addEventListener(name, func, false); 
        }
    }
	
//检测设备
	function checkDevice(){
		$("body").append("<object id=\"ocr\" type=\"application/x-eloamplugin\"  name=\"ocr\"  width=\"0\"  height=\"0\"></object>");
		try
		  {
			if(ocr().Global_InitDevs()){
				ocr().Global_DeinitDevs();
				device=true;
				return device;
			}
		  }
		catch(err)
		  {
			device=false;
		  }
		$("#ocr").remove();
	}
	//打开摄像头
	function OpenVideo()
	{	
			Video = plugin().Device_CreateVideo(DeviceMain, -1, 1);
			if (Video)
			{
				view().View_SelectVideo(Video);
				view().View_SetText("正在打开高拍仪，请等待...", 0);
			}				

	}
	
	//关闭摄像头
	function CloseVideo()
	{
		if (Video)
		{
			view().View_SetText("", 0);
			plugin().Video_Release(Video);
			Video = null;
		}	
		
		plugin().Global_DeinitDevs();
	}
	

     /**
      * 高拍仪初始化
      * */
	function Load()
	{
		//设备接入和丢失
		//type设备类型， 1 表示视频设备， 2 表示音频设备
		//idx设备索引
		//dbt 1 表示设备到达， 2 表示设备丢失
		addEvent(plugin(), 'DevChange', function (type, idx, dbt) 
		{
			if(1 == type)//视频设备
			{
				if(1 == dbt)//设备到达
				{
					var deviceType = plugin().Global_GetEloamType(1, idx);
					if(1 == deviceType)//主摄像头
					{
							DeviceMain = plugin().Global_CreateDevice(1, idx);							
							var subType = plugin().Device_GetSubtype(DeviceMain);
								OpenVideo();//是主头自动打开视频
					}
				}
				else if(2 == dbt)//设备丢失
				{
			
				}
			}
		});
	
		view().Global_SetWindowName("view");
		plugin().Global_InitDevs();
	}
		

    /**
     * 高拍仪拍照
     * @param showName      节点名字
     * @param listName      上传图片名字
     */
	function Scan( showName, listName)
	{	
		var img = plugin().Video_CreateImage(Video, 0, view().View_GetObject());
		view().View_PlayCaptureEffect();
		var base64=plugin().Image_GetBase64(img,2,0);
		var result = updateBase64('data:image/jpeg;base64,' + base64);
		if (result.status) {
			//添加上传图片
			
			$(showName).append("<div class=\"col-xs-12 col-sm-4 mb15\">\n" +
					"<div class=\"thumbnail images-box\"><input type=\"hidden\" name=\""+listName+"\" value=\"" + result.url + "\">\n" +
					"<img src=\"" + result.domain + result.url + "\">\n" +
					"</div>\n" +
					"<div class=\"caption\">\n" +
					"<div class=\"btn btn-block btn-danger deletetCover\" onclick=\"$(this).parent().parent().remove()\"><i class=\"iconfont icon-remove\"></i>&nbsp;删除</div>\n" +
					"</div>\n" +
			"</div>");
			msgTool["success"]("添加资料图片成功", '提示');
		} else {
			msgTool["error"](result.message, '提示');
		}	

	}
	
	

    /******************二代证阅读器********************/	
	function ReadIDCard()
	{
		$("body").append("<object id=\"view\" type=\"application/x-eloamplugin\"  name=\"ocr\"  width=\"0\"  height=\"0\"></object>");
		var obj={"name":"","sex":"","nation":"","birthday":"","address":"","idcard":"","cardFrontPicture":"","cardBackPicture":"","message":null};			
	     plugin().Global_InitDevs();
		if(plugin().Global_InitIdCard())
		{
			var ret = plugin().Global_ReadIdCard();
			if(ret)
			{
                 obj.name=plugin().Global_GetIdCardData(1);	
				 obj.sex=plugin().Global_GetIdCardData(2);		 
				 obj.nation=plugin().Global_GetIdCardData(3)+"族";		 
				 obj.birthday=plugin().Global_GetIdCardData(4)+plugin().Global_GetIdCardData(5)+plugin().Global_GetIdCardData(6);		 
				 obj.address=plugin().Global_GetIdCardData(7);	
                 obj.idcard=plugin().Global_GetIdCardData(8);	 	
                 
             	var img = plugin().Global_GetIdCardImage(2);//1表示头像， 2表示正面， 3表示反面 ...
                 obj.IDcard_frontImg_base64=plugin().Image_GetBase64(img,2,0);
         		
         		var img = plugin().Global_GetIdCardImage(3);//1表示头像， 2表示正面， 3表示反面 ...
         		 obj.IDcard_backImg_base64=plugin().Image_GetBase64(img,2,0);
    

			}	else
			{
				obj.message= "读取二代证失败！";
			}
			
			plugin().Global_DeinitIdCard();
			plugin().Global_DeinitDevs();
		}
		else
		{
			obj.message="初始化二代证阅读器失败！";
        }
		$("#view").remove();
		return obj;
	}	